package com.gomore.opple.module.incomeandexpense.adapter;

import android.content.Context;

import com.gomore.opple.R;
import com.gomore.opple.common.GlobalConstant;
import com.gomore.opple.rest.applybill.ApplyHist;
import com.gomore.opple.utils.BigDecimalUtils;
import com.gomore.opple.utils.DateUtil;
import com.gomore.opple.widgets.adapter.CommonAdapter;
import com.gomore.opple.widgets.adapter.ViewHolder;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by asus on 2017/5/25.
 */
public class InComeAndExpenseAdapter extends CommonAdapter<ApplyHist> {

    Context mContext;

    public InComeAndExpenseAdapter(Context context, int layoutId, List<ApplyHist> applyHists) {
        super(context, layoutId, applyHists);
        mContext = context;
    }

    @Override
    protected void convert(ViewHolder holder, final ApplyHist applyHist, final int position) {
        if (applyHist.getType() != null) {
            holder.setText(R.id.type, GlobalConstant.applyType.getNameByType(applyHist.getType()));
        }
        if (applyHist.getAmount() != null) {
            int compare = applyHist.getAmount().compareTo(new BigDecimal(0));
            if (compare == 1) {
                holder.setText(R.id.in_or_out, "返佣");
            } else {
                holder.setText(R.id.in_or_out, "提现");
            }
            String money = BigDecimalUtils.forMate(applyHist.getAmount()).toString().trim();
            if (money.contains("-")) {
                holder.setText(R.id.money, money);
            } else {
                if (money.equals("0.00")) {
                    holder.setText(R.id.money, money);
                } else {
                    holder.setText(R.id.money, "+" + money);
                }
            }
        }
        if (applyHist.getCreateDate() != null) {
            holder.setText(R.id.time, DateUtil.fomatforDate(applyHist.getCreateDate(), DateUtil.DATE_FORMATTER_1));
        }
    }
}

